package com.css.fxfzypg.modules.baseData.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.baseData.entity.DisasterScene;
import com.css.fxfzypg.modules.baseData.entity.EmergencyCountermeasure;
import com.css.fxfzypg.modules.baseData.queryParams.DisasterSceneQueryParams;
import com.css.fxfzypg.modules.baseData.queryParams.EmergencyCountermeasureQueryParams;
import com.css.fxfzypg.modules.baseData.repository.DisasterSceneRepository;
import com.css.fxfzypg.modules.baseData.repository.EmergencyCountermeasureRepository;
import com.css.fxfzypg.modules.baseData.service.DisasterSceneService;
import com.css.fxfzypg.modules.baseData.service.EmergencyCountermeasureService;
import com.css.fxfzypg.util.PlatformDateUtils;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.UUIDGenerator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service
public class EmergencyCountermeasureServiceImpl implements EmergencyCountermeasureService {

    @Resource
    EmergencyCountermeasureRepository emergencyCountermeasureRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public EmergencyCountermeasure updateEmergencyCountermeasure(EmergencyCountermeasure emergencyCountermeasure) {

        emergencyCountermeasure.setEcUpdatetime(PlatformDateUtils.getCurrentTimestamp());
        emergencyCountermeasureRepository.updateEmergencyCountermeasure(emergencyCountermeasure);

       return null;
    }

    @Override
    @Transactional
    public EmergencyCountermeasure saveEmergencyCountermeasure(EmergencyCountermeasure emergencyCountermeasure) {
        emergencyCountermeasure.setEcId(UUIDGenerator.getUUID());
        emergencyCountermeasure.setEcStatus(YNEnum.Y.toString());
        emergencyCountermeasure.setEcCreatetime(PlatformDateUtils.getCurrentTimestamp());
        return emergencyCountermeasureRepository.saveEmergencyCountermeasure(emergencyCountermeasure);
    }

    @Override
    public Map<String,Object> getAllEmergencyCountermeasure(EmergencyCountermeasureQueryParams queryParams) {
        return emergencyCountermeasureRepository.getAllEmergencyCountermeasureParams(queryParams);
    }

    @Override
    public EmergencyCountermeasure getEmergencyCountermeasureById(String id) {

        return emergencyCountermeasureRepository.getEmergencyCountermeasureById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteEmergencyCountermeasure(List<String> ids) {
        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        emergencyCountermeasureRepository.deleteEmergencyCountermeasuresById(ids,timestamp);
    }

//    @Override
//    public List<DisasterScene> getAll() {
//
//        return disasterSceneRepository.getAll();
//    }

    //   @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void importExcel(MultipartFile file) throws IOException {
//        List<DisasterScene> disasterScenes = FileUtil.importExcel(file, DisasterScene.class);
//        for(int i = 0 ; i<disasterScenes.size();i++){
//            disasterScenes.get(i).setDsId(UUIDGenerator.getUUID());
//            disasterScenes.get(i).setDsStatus(YNEnum.Y.toString());
//
//        }
//        disasterSceneRepository.importExcel(disasterScenes);
//    }
}
